/**
 * @Project: LizhiFM
 * @Author: squll
 * @Date: 2013-10-8
 * @Copyright: (c) 2013 广州市一把伞网络科技有限公司 All rights reserved.
 */

package com.hubujun.driverlicense.db;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class SQLiteDatabaseHelper {

	private SQLiteDatabase mData;

	public SQLiteDatabaseHelper() {
		mData = null;
	}

	public static SQLiteDatabaseHelper openOrCreateDatabase(String path) {
		SQLiteDatabaseHelper d1 = null;
		SQLiteDatabaseHelper d2 = new SQLiteDatabaseHelper();
		try {
			d2.mData = SQLiteDatabase.openOrCreateDatabase(path, null);
			d2.mData.enableWriteAheadLogging();
		} catch (Exception exception) {
		}
		if (d2.mData != null)
			d1 = d2;
		return d1;
	}

	public static SQLiteDatabaseHelper b(String s) {
		SQLiteDatabaseHelper d1 = null;
		SQLiteDatabaseHelper d2 = new SQLiteDatabaseHelper();
		try {
			// d2.a =
			// info.guardianproject.database.sqlcipher.SQLiteDatabase.openOrCreateDatabase(s,
			// null);
		} catch (Exception exception) {
		}
		// if (d2.a != null)
		// d1 = d2;
		return d1;
	}

	// private boolean isEnyDatabase() {
	// boolean flag = false;
	// // if (a != null && mData != null)
	// // Assert.assertTrue("two db not null at same time", false);
	// // if (a == null && mData == null)
	// // Assert.assertTrue("two db null at same time", false);
	// // if (a != null)
	// // flag = true;
	// return flag;
	// }

	public int update(String table, ContentValues values, String whereClause, String[] whereArgs) {
		int i;
		// if (isEnyDatabase())
		// i = a.update(table, values, whereClause, whereArgs);
		// else
		i = mData.update(table, values, whereClause, whereArgs);
		return i;
	}

	public int delete(String table, String whereClause, String[] whereArgs) {
		int i;
		// if (isEnyDatabase())
		// i = a.delete(table, whereClause, whereArgs);
		// else
		i = mData.delete(table, whereClause, whereArgs);
		return i;
	}

	public long insert(String table, String nullColumnHack, ContentValues values) {
		long l;
		// if (isEnyDatabase())
		// l = a.insert(table, nullColumnHack, values);
		// else
		l = mData.insert(table, nullColumnHack, values);
		return l;
	}

	public Cursor rawQuery(String sql, String[] selectionArgs) {
		Cursor cursor;
		// if (isEnyDatabase())
		// cursor = a.rawQuery(sql, selectionArgs);
		// else
		cursor = mData.rawQuery(sql, selectionArgs);
		return cursor;
	}

	public Cursor query(String table, String[] columns, String selection, String[] selectionArgs, String orderBy) {
		Cursor cursor;
		// if (isEnyDatabase())
		// cursor = a.query(s, as, s1, as1, null, null, s2);
		// else
		cursor = mData.query(table, columns, selection, selectionArgs, null, null, orderBy);
		return cursor;
	}

	public Cursor query(String table, String[] columns, String selection, String[] selectionArgs, String orderBy, String limit) {
		Cursor cursor;
		cursor = mData.query(table, columns, selection, selectionArgs, null, null, orderBy, limit);
		return cursor;
	}

	public Cursor query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String orderBy, String limit) {
		Cursor cursor;
		cursor = mData.query(table, columns, selection, selectionArgs, groupBy, null, orderBy, limit);
		return cursor;
	}

	public void close() {
		try {
			// if(a != null)
			// {
			// a.close();
			// a = null;
			// }
			if (mData != null) {
				mData.close();
				mData = null;
			}
		} catch (Exception e) {
		}
	}

	public long replace(String table, String nullColumnHack, ContentValues initialValues) {
		long l;
		// if (isEnyDatabase())
		// l = a.replace(s, s1, contentvalues);
		// else
		l = mData.replace(table, nullColumnHack, initialValues);
		return l;
	}

	public void beginTransaction() {
		// if (isEnyDatabase())
		// a.beginTransaction();
		// else
		mData.beginTransactionNonExclusive();
	}

	public void endTransaction() {
		// if (isEnyDatabase())
		// a.endTransaction();
		// else
		mData.endTransaction();
	}

	public void execSQL(String sql) {
		// if (isEnyDatabase())
		// a.execSQL(sql);
		// else
		mData.execSQL(sql);
	}

	public void setTransactionSuccessful() {
		// if (isEnyDatabase())
		// a.setTransactionSuccessful();
		// else
		mData.setTransactionSuccessful();
	}

	public boolean inTransaction() {
		boolean flag;
		// if (isEnyDatabase())
		// flag = a.inTransaction();
		// else
		flag = mData.inTransaction();
		return flag;
	}

	public int getVersion() {
		// if (isEnyDatabase())
		// return a.getVersion();
		// else
		return mData.getVersion();
	}

	public void setVersion(int version) {
		// if (isEnyDatabase())
		// a.setVersion(version);
		// else
		mData.setVersion(version);
	}

}
